﻿namespace LeetCodeProject._0001_1000._101_200._101_110._110;

public class Solution
{
    public bool IsBalanced(TreeNode root)
    {
        return root == null ||
               IsBalanced(root.left) && IsBalanced(root.right) && Math.Abs(Depth(root.left) - Depth(root.right)) <= 1;
    }

    private int Depth(TreeNode root)
    {
        return root == null ? 0 : Math.Max(Depth(root.left), Depth(root.right)) + 1;
    }
}